package chapter_09_composite.p9_3;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by CharloYao on 2017/3/6.
 */
public class Folder implements IFile {

    private String name;
    private List<IFile> folder;

    private int deep;

    public Folder(String name) {
        this.name = name;
        folder = new ArrayList<>();
    }

    /**
     * Folder独有的方法，File类没有，安全式的组合模式
     * @param file
     * @return
     */
    public boolean add(IFile file){
        folder.add(file);
        file.setDeep(this.deep + 1);
        return true;
    }

    /**
     * Folder独有的方法，File类没有，安全式的组合模式
     * @param file
     * @return
     */
    public boolean remove(IFile file){
        folder.remove(file);
        return true;
    }

    public List<IFile> getAllComponent(){
        return folder;
    }

    @Override
    public IFile getComposite() {
        return this;
    }

    @Override
    public void sampleOperation() {
        System.out.println("一些常规的操作");
    }

    @Override
    public int getDeep() {
        return deep;
    }

    @Override
    public void setDeep(int deep) {
        this.deep = deep;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
